home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
626-637
/
disk_632
/
printfiles
/
source
/
prf_main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
9KB
|
339 lines
/* prf_main.c */
/* V1.1 9-3-92 */
#include "prf.h"
/* ------------------------------------------------------------------- */
/* for cback.o startup */
/* ------------------------------------------------------------------- */
long _stack = 4000;
char *_procname = "*PrintFiles V1.1*";
long priority = 0;
long _BackGroundIO = 0;
extern BPTR _Backstdout;
/* ----------------------------------------------------------------- */
void CheckCmdLine(struct prf_info *,int,union wbstart);
void SetSTFlags(struct prf_info *,UBYTE *);
struct IntuitionBase *IntuitionBase;
struct Library *WorkbenchBase;
struct Library *GadToolsBase;
struct Library *AslBase;
struct Library *IconBase;
struct RxsLib *RexxSysBase;
struct GfxBase *GfxBase;
void main(int argc ,union wbstart argv)
{
struct prf_info *info;
long end = (long)FALSE;
if(info = (struct prf_info *)calloc(1,sizeof(struct prf_info)))
{
if(OpenLibs(info))
{
if(OpenApp(info))
{
CheckCmdLine(info,argc,argv);
SetPrfSignals(info);
if(info->flags & FLAG_OPENWINDOW)
{
info->flags ^= FLAG_OPENWINDOW;
ChangeApp(info);
}
if(info->flags & FLAG_IMMEDIATE)
{
info->flags ^= FLAG_IMMEDIATE;
PrintQueue(info);
}
while(!end)
{
SetPrfSignals(info);
Wait(info->signals);
if(DoCommand(info,HandleMsgs(info)) == CMD_QUIT) end = (long)TRUE;
}
CloseApp(info);
}
}
CloseLibs(info);
}
exit(0);
}
long OpenLibs(struct prf_info *info)
{
if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",SYSTEM_VERSION))
{
if(WorkbenchBase = OpenLibrary("workbench.library",SYSTEM_VERSION))
{
if(AslBase = OpenLibrary("asl.library",SYSTEM_VERSION))
{
if(GadToolsBase = OpenLibrary("gadtools.library",SYSTEM_VERSION))
{
if(IconBase = OpenLibrary("icon.library",SYSTEM_VERSION))
{
if(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",SYSTEM_VERSION))
{
if(info->PubScr = LockPubScreen( "Workbench" ))
{
info->BarHeight = (ULONG)((long)(info->PubScr->BarHeight));
PwdTags[3].ti_Data += info->BarHeight ;
SwdTags[3].ti_Data += info->BarHeight ;
if(info->VisualInfo = GetVisualInfo(info->PubScr,TAG_DONE ))
{
NewList(&info->FileList);
AttemptOpenRexx(info);
Prf_Reset(info);
return ((long)TRUE);
}
}
}
}
}
}
}
}
return ((long)FALSE);
}
void CloseLibs(struct prf_info *info)
{
struct Node *n;
if(info)
{
CloseRexx(info);
if(info->Swd)CloseSwd(info);
if(info->Pwd)ClosePwd(info);
if(info->VisualInfo) FreeVisualInfo(info->VisualInfo);
if(info->PubScr)UnlockPubScreen(0L,info->PubScr);
while(n = (struct Node *)RemHead(&info->FileList))free((struct FileNameNode *)n);
free(info);
}
if (GfxBase) CloseLibrary((struct Library *)GfxBase);
if (IconBase) CloseLibrary(IconBase);
if (GadToolsBase) CloseLibrary(GadToolsBase);
if (AslBase) CloseLibrary(AslBase);
if (WorkbenchBase) CloseLibrary(WorkbenchBase);
if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
}
void Prf_Reset(struct prf_info *info)
{
struct Node *n;
while(n = (struct Node *)RemHead(&info->FileList))free((struct FileNameNode *)n);
info->Lines = DEFAULT_LINES;
info->Rmargin = DEFAULT_RMARGIN;
info->Lmargin = DEFAULT_LMARGIN;
info->Lines = DEFAULT_LINES;
info->flags = DEFAULT_FLAGS;
info->Columns = DEFAULT_RMARGIN - DEFAULT_LMARGIN;
strcpy(info->Headline, DEFAULT_HEADLINE);
strcpy(info->Footline, DEFAULT_FOOTLINE);
RefreshPwd(info);
RefreshSwd(info);
}
void SetPrfSignals(struct prf_info *info)
{
info->signals = 0L;
if(info->Swd) info->signals |= (1L << info->Swd->UserPort->mp_SigBit);
if(info->Pwd) info->signals |= (1L << info->Pwd->UserPort->mp_SigBit);
if(info->appPort) info->signals |= (1L << info->appPort->mp_SigBit);
if(info->rexxPort) info->signals |= (1L << info->rexxPort->mp_SigBit);
if(info->prtPort) info->signals |= (1L << info->prtPort->mp_SigBit);
}
long HandleMsgs(struct prf_info *info)
{
long rc = CMD_NEUTRAL;
if(info->Swd)
{
while(info->imsg = GT_GetIMsg(info->Swd->UserPort))
{
long rc1;
if((rc1 = HandleImsg(info)) != CMD_NEUTRAL)rc = rc1;
GT_ReplyIMsg(info->imsg);
}
}
if(info->Pwd)
{
while(info->imsg = GT_GetIMsg(info->Pwd->UserPort))
{
long rc1;
if((rc1 = HandleImsg(info)) != CMD_NEUTRAL)rc = rc1;
GT_ReplyIMsg(info->imsg);
}
}
if(info->appPort)
{
while(info->amsg = (struct AppMessage *)GetMsg(info->appPort))
{
long rc1;
if((rc1 = HandleAmsg(info)) != CMD_NEUTRAL)rc = rc1;
ReplyMsg((struct Message *)info->amsg);
}
}
if(info->rexxPort)
{
while(info->rmsg = (struct RexxMsg *)GetMsg(info->rexxPort))
{
long rc1;
if((rc1 = HandleRexxMsg(info)) != CMD_NEUTRAL)rc = rc1;
ReplyMsg((struct Message *)info->rmsg);
}
}
if(info->prtPort)
{
}
return (rc);
}
void CheckCmdLine(struct prf_info *info,int argc,union wbstart argv)
{
struct DiskObject *dobj;
UBYTE *p,buffer[256],**tta;
ULONG a,b;
long cmd = CMD_INSERTTAIL;
int i;
if(argc)
{
if(argc > 1)
{
for(i=1;i<argc;i++)
{
switch(argv.args[i][0])
{
case '-': SetSTFlags(info,&argv.args[i][1]);
break;
default : info->flags |= FLAG_IMMEDIATE;
info->Special1 = (APTR)&argv.args[i][0];
info->Special2 = (APTR)&cmd;
InsertName(info);
info->Special1 = NULL;
info->Special2 = NULL;
break;
}
}
}
}
else
{
if(dobj = GetDiskObject(argv.msg->sm_ArgList->wa_Name))
{
tta = dobj->do_ToolTypes;
if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_WD))
{
i = sscanf(p,"%ld %ld",&a,&b);
if(i == 2)
{
SwdTags[0].ti_Data = a;
SwdTags[1].ti_Data = b;
}
info->flags |= FLAG_OPENWINDOW;
}
if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_FLAGS))
{
strcpy(buffer,p);
SetSTFlags(info,buffer);
}
if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_HEAD))
{
strcpy(info->Headline,p);
}
if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_FOOT))
{
strcpy(info->Footline,p);
}
if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_LMARGIN))
{
info->Lmargin = atol(p);
if(info->Lmargin > info->Rmargin)info->Lmargin = DEFAULT_LMARGIN;
if((info->Columns = (info->Rmargin - info->Lmargin)) == 0)
info->Columns = 1;
}
if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_RMARGIN))
{
info->Rmargin = atol(p);
if(info->Rmargin < info->Lmargin)info->Rmargin = DEFAULT_RMARGIN;
if((info->Columns = (info->Rmargin - info->Lmargin)) == 0)
info->Columns = 1;
}
if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_LINES))
{
info->Lines = atol(p);
}
}
if(argv.msg->sm_NumArgs > 1)
{
info->flags |= FLAG_IMMEDIATE;
for(i = 1; i < argv.msg->sm_NumArgs;i++)
{
NameFromLock(argv.msg->sm_ArgList[i].wa_Lock,buffer,STR_SIZE);
AddPart(buffer,argv.msg->sm_ArgList[i].wa_Name,STR_SIZE);
info->Special1 = (APTR)buffer;
info->Special2 = (APTR)&cmd;
InsertName(info);
info->Special1 = NULL;
info->Special2 = NULL;
}
}
}
}
/* ----------------------------------------------------------------- */
void SetSTFlags(struct prf_info *info,UBYTE *buffer)
{
int i;
for(i=0;i< strlen(buffer);i++)
{
switch(*(buffer+i))
{
case CLI_TIME : info->flags |= FLAG_TIME;
break;
case CLI_FF : info->flags |= FLAG_FF;
break;
case CLI_FILE : info->flags |= FLAG_FILE;
break;
case CLI_PAGE : info->flags |= FLAG_PAGE;
break;
case CLI_LINE : info->flags |= FLAG_LINE;
break;
case CLI_CRLF : info->flags |= FLAG_CRLF;
break;
case CLI_DRAFT : DoCommand(info,CMD_DRAFT);
break;
case CLI_LQ : DoCommand(info,CMD_LQ);
break;
case CLI_DATE : info->flags |= FLAG_DATE;
break;
case CLI_WD : info->flags |= FLAG_OPENWINDOW;
break;
case CLI_10CPI : DoCommand(info,CMD_10CPI);
break;
case CLI_12CPI : DoCommand(info,CMD_12CPI);
break;
case CLI_15CPI : DoCommand(info,CMD_15CPI);
break;
case CLI_PITCH6 : DoCommand(info,CMD_PITCH6);
break;
case CLI_PITCH8 : DoCommand(info,CMD_PITCH8);
break;
default : break;
}
}
}
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */